package com.foreknow.practice.lala;

import java.util.Scanner;

/**
 * 方法练习
 */
public class Test12 {
    //7．菜单
    public static String  menu(){
        Scanner input = new Scanner(System.in);
        String answer = "";//  y / n
        //定义余额
        double balance=10000.0;
        //定义存款金额
        double deposit=0.0;
        //取款金额
        double withdrawal = 0.0;
        //新密码
        String newPassword = "";
        //旧密码
        String password1="test";
        //旧账号
        String username = "test";
//        Test12.login()
        do {
            System.out.println("1．查询余额");
            System.out.println("2．存款");
            System.out.println("3．取款");
            System.out.println("4．修改密码");
            System.out.println("5．退出");
            //请选择菜单进入
            System.out.println("请选择菜单进入");
            int choice = input.nextInt();
            switch (choice) {
                case 1:
                    //1．查询余额的方法
                    System.out.println("您的余额为:"+balance);
                    break;
                case 2:
                    //2．存款
                    System.out.println("请输入您要存款的金额");
                    deposit = input.nextDouble();
                    if (deposit>=100&&deposit<=20000&&deposit%100!=0){
                        deposit+=balance;//总余额
                        System.out.println("存入成功,余额为:"+deposit);
                    }else if (deposit>20000){
                        System.out.println("存款金额超过20000");
                    }else if (deposit>1&&deposit<100){
                        System.out.println("请输入一百的整数存款");

                    }else {
                        System.out.println("存款金额错误");
                    }
                    break;
                case 3:
                    //3．取款
                    System.out.println("请输入您要取款的金额");
                    withdrawal=input.nextDouble();
                    if (withdrawal>balance){
                        System.out.println("余额不足");
                    }else if (withdrawal>3000){
                        System.out.println("单次取款金额超过3000元");
                    }else if (withdrawal>100&&withdrawal<3000&&withdrawal%100!=0){
                        System.out.println("请取出100的整数倍存款");
                    }else if (withdrawal<100){
                        System.out.println("取款金额错误");
                    }else {
                        System.out.println("取款成功,当前余额:"+(balance-withdrawal));
                    }

                    break;
                case 4:
                    //旧密码
                     password1="test";
                     //输入旧密码2
                    String password2 = "test";
                    System.out.println("请输入旧密码");

                    password2 =input.next();
                    System.out.println("请输入新密码");
                    newPassword = input.next();
                    System.out.println("再次输入新密码");
                  String  newPassword1 =input.next();
                    if (password1.equals(password2) && newPassword.equals(newPassword1)){
                        System.out.println("密码修改成功,当前密码为:"+newPassword);
                    }else{
                        System.out.println("两次输入密码不一致，请重新输入");

                            if (password2!=password1){
                                System.out.println("旧密码输入错误,当前密码为:"+password1);
                            }else if(password1.equals(password2) && newPassword!=newPassword1){
                                System.out.println("两次新密码不一致,请从新输入,当前密码为:"+password1);
                            }

                    }


                    break;
                case 5:
                    System.out.println("退出成功");
                    System.exit(0);
                    break;
                default:
                    System.out.println("非法操作");
                    break;

            }
            System.out.println("是否继续 y / n");
            answer=input.next();
        }while (answer.equals("y"));
        //but
        if (answer.equals("n")){
            System.out.println("退出成功");
        }else {
            while (true){
                System.out.println("输入错误，从新输入");
                answer=input.next();
                if (answer.equals("y")) {
                    return null;
                }

            }
        }
        if (answer.equals("n")){
//            System.out.println("退出成功");
            System.exit(1);
//            System.out.println("Cannot be done...");
        }

        return menu();
    }
    //6．	登录
        public static boolean login(){

            boolean isRegister ;
            while (isRegister=true) {
                for (int i = 1; i <= 3; i++) {
                    System.out.println("***欢迎登录*****");
                    System.out.println("****中国人民银行****");
                    System.out.println("****版本1.0******");
                    Scanner input = new Scanner(System.in);
                    //账号
                    String username = "test";
                    System.out.println("请输入账号:");
                    username = input.next();
                    //密码
                    String password = "test";
                    System.out.println("请输入密码:");
                    password = input.next();
                    if (username.equals("test") && password.equals("test")) {
                        System.out.println("登录成功");
                        String menu = Test12.menu();
                        System.out.println(menu);
                    } else {
                        if (i < 3) {
                            System.out.println("账户名或密码错误,请从新输入,今日还剩下" + (3 - i) + "次机会");
                        } else {
                            System.out.println("密码错误,吞卡,请联系工作人员");
                            System.exit(0);
                        }

                    }
                }
                break;
            }


//怎么让他循环回去  循环回去了
            //取款和修改密码
        return false;
        }

    //Main主方法来进行测试
    public static void main(String[] args) {

        boolean login=Test12.login();
        System.out.println(login);
        if (login==true){
            String menu= Test12.menu();
            System.out.println(menu);
        }

    }
}
